<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import { message } from 'ant-design-vue';
import { getSourceFileUrlApi } from '@/api/study/course';
const props = defineProps<{
  sourceId: string;
}>();

const sourceFileUrl = ref<string | null>(null)

// 获取具体资源URL
const fetchSourceFileInfo = async (sourceId: string) => {
  try {
    const response = await getSourceFileUrlApi(sourceId);
    sourceFileUrl.value = response;
  }
  catch (error) {
    message.error("获取资源信息失败")
  }
}

watch(() => props.sourceId, (newSourceId: string) => {
  fetchSourceFileInfo(newSourceId)
})

onMounted(() => {
  fetchSourceFileInfo(props.sourceId)
})
</script>

<template>
  <div class="container">
    <div class="navigation">
      <iframe
        v-if="sourceFileUrl"
        :src="sourceFileUrl"
        width="100%"
        height="100%"
        style="border: none; margin-bottom: 0px;"
      />
      <p v-else>
        PDF 暂时无法获取
      </p>
    </div>
  </div>
</template>

<style scoped>
.container {
  padding: 20px;
  background-color: #f7f8fc;
  border-radius: 8px;
  margin-bottom: 20px;
  position: relative;

}

.navigation {
  padding: 20px;
  background-color: #fff;
  box-shadow: 0 4px 12px rgba(0.1, 0.1, 0.1, 0.1);
  height: 70vh;

}
</style>
